<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        let arr = [1,2,4,5,7,10];
        //算总和
        // let arr1 = arr.reduce(function (temp,item,index) {
        //     return temp+item;
        // })
        // 第一个参数就是指的是中间值
        let arr1 = arr.reduce(function (temp,item,index) {
            if(index==arr.length-1){
                return (temp+item)/arr.length;
            }else{
                return temp+item;
            }
        })
        alert(arr1)
    </script>
</head>
<body>

</body>
</html>